﻿//-----------------------------------------------------------------------
// <copyright file="TrackerProxy.cs" company="Numbrella foundation">
// Copyright (c) Numbrella foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Numbrella.Interaction
{
	using System.Collections.Generic;
	using System.ServiceModel;
	using System.ServiceModel.Channels;
	
	/// <summary>
	/// Represents proxy for transparent interaction with <see cref="ITrackerService"/> WCF service.
	/// </summary>
	public class TrackerProxy : ClientBase<ITrackerService>, ITrackerService
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="TrackerProxy"/> class.
		/// </summary>
		public TrackerProxy()
		{
		}        

		/// <summary>
		/// Initializes a new instance of the <see cref="TrackerProxy"/> class using given endpoint configuration name.
		/// </summary>
		/// <param name="endpointConfigurationName">Endpoint configuration name.</param>
		public TrackerProxy(string endpointConfigurationName) :
			base(endpointConfigurationName)
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="TrackerProxy"/> class using given endpoint configuration name and remote address
		/// in string format.
		/// </summary>
		/// <param name="endpointConfigurationName">Endpoint configuration name.</param>
		/// <param name="remoteAddress">Remote address as string.</param>
		public TrackerProxy(string endpointConfigurationName, string remoteAddress) :
			base(endpointConfigurationName, remoteAddress)
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="TrackerProxy"/> class using given endpoint configuration name and remote address.
		/// </summary>
		/// <param name="endpointConfigurationName">Endpoint configuration name.</param>
		/// <param name="remoteAddress">Remote address.</param>
		public TrackerProxy(string endpointConfigurationName, EndpointAddress remoteAddress) :
			base(endpointConfigurationName, remoteAddress)
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="TrackerProxy"/> class using given binding configuration and remote address.
		/// </summary>
		/// <param name="binding">Endpoint configuration name.</param>
		/// <param name="remoteAddress">Remote address.</param>
		public TrackerProxy(Binding binding, EndpointAddress remoteAddress) :
			base(binding, remoteAddress)
		{
		}        

		/// <summary>
		/// Retrieves description of a problem that has not been solved yet.
		/// </summary>
		/// <returns>Pending problem description.</returns>
		public ProblemDefinition GetPendingProblem()
		{
			return Channel.GetPendingProblem();
		}

        /// <summary>
        /// Adds new problem to tracker.
        /// </summary>
        /// <param name="name">Unique problem name.</param>
        /// <param name="description">Problem description.</param>
        /// <param name="implementation">Problem implementation aspects.</param>
        public void AddProblem(string name, ProblemDescription description, ProblemImplementation implementation)
        {
            Channel.AddProblem(name, description, implementation);
        }

        /// <summary>
        /// Notifies tracker about pending problem.
        /// </summary>
        /// <param name="problemName">Unique problem name.</param>
        /// <param name="problemHostingPort">Port on the client where problem hosting service is listening.</param>
        public void ReadyForSeed(string problemName, int problemHostingPort)
		{
			Channel.ReadyForSeed(problemName, problemHostingPort);
		}

        /// <summary>
        /// Notifies tracker that problem must be deleted.
        /// </summary>
        /// <param name="name">Unique problem name.</param>
        public void DeleteProblem(string name)
		{
			Channel.DeleteProblem(name);
		}

		/// <summary>
		/// Notifies tracker that task of a given problem was solved, so tracker can increase rating for user who solved that task.
		/// </summary>
		/// <param name="problemName">Unique problem name.</param>
		/// <param name="taskId">Unique identifier of the solved task.</param>
		/// <param name="userNames">Names of the users participating in solving the task.</param>
		public void NotifyAboutTaskCompletion(
			string problemName, int taskId, IEnumerable<string> userNames)
        {
            Channel.NotifyAboutTaskCompletion(problemName, taskId, userNames);
        }
	}
}
